@extends('admin.layouts')
@section('content')
    <!--面包屑导航 开始-->
    <div class="crumb_warp">
        <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
        <i class="fa fa-home"></i> <a href="#">首页</a> &raquo; 添加文章
    </div>
    <!--面包屑导航 结束-->

	<!--结果集标题与导航组件 开始-->
	<div class="result_wrap">
        <div class="result_title">
            <h3>文章管理</h3>
            <div class="mark">
                @if(is_object($errors))
                    @if(count($errors)>0)
                        @foreach($errors->all() as $error)
                            {{$error}}
                        @endforeach
                    @endif
                @else
                    <p>{{$errors}}</p>
                @endif
            </div>
        </div>
        <div class="result_content">
            <div class="short_wrap">
                <a href="{{url('admin/article/create')}}"><i class="fa fa-plus"></i>添加分类</a>
                <a href="{{url('admin/article')}}"><i class="fa fa-recycle"></i>全部分类</a>
            </div>
        </div>
    </div>
    <!--结果集标题与导航组件 结束-->

    <div class="result_wrap">
        <form action="{{url('admin/article/'.$field->art_id)}}" method="post">
            <input type="hidden" name="_method" value="put">
            {{csrf_field()}}
            <table class="add_tab">
                <tbody>
                    <tr>
                        <th width="120">文章分类</th>
                        <td>
                            <select name="cate_id">
                                <option value="1">==分类==</option>
                                @foreach($data as $d)
                                    <option value="{{$d->cate_id}}"
                                        @if($field->cate_id==$d->cate_id) selected @endif
                                    >{{$d->_cate_name}}</option>
                                @endforeach
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>文章标题</th>
                        <td>
                            <input type="text" class="lg" name="art_title" value="{{$field->art_title}}">
                        </td>
                    </tr>
                    <tr>
                        <th>文章作者</th>
                        <td>
                            <input type="text" class="lg" name="art_editor" value="{{$field->art_editor}}">
                        </td>
                    </tr>
                    <tr>
                        <th>关键字</th>
                        <td>
                            <input type="text" class="lg" name="art_tag" value="{{$field->art_tag}}">
                        </td>
                    </tr>
                    <tr>
                        <th>文章描述</th>
                        <td>
                            <textarea class="lg" name="art_discription">{{$field->art_discription}}</textarea>
                        </td>
                    </tr>
                    <tr>
                        <th>文章内容</th>
                        <td>
                            <script type="text/javascript" charset="utf-8" src="{{asset('resources/org/ueditor')}}/ueditor.config.js"></script>
                            <script type="text/javascript" charset="utf-8" src="{{asset('resources/org/ueditor')}}/ueditor.all.min.js"> </script>
                            <script type="text/javascript" charset="utf-8" src="{{asset('resources/org/ueditor')}}/lang/zh-cn/zh-cn.js"></script>
                            <script id="editor" name="art_content" type="text/plain" style="width:800px;height:500px;">{!! $field->art_content !!}</script>
                            <script type="text/javascript">
                                //实例化编辑器
                                //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
                                var ue = UE.getEditor('editor');
                            </script>
                            <style>
                                .edui-default{line-height: 28px;}
                                div.edui-combox-body,div.edui-button-body,div.edui-splitbutton-body
                                {overflow: hidden; height:20px;}
                                div.edui-box{overflow: hidden; height:22px;}
                            </style>
                        </td>
                    </tr>
                    <tr>
                        <th>文章封面</th>
                        <td>
                            <input type="text" class="ls" name="art_thumb" value="{{$field->art_thumb}}">
                            <input type="file" id="uploadFile" name="art_thumb_file" multiple>
                            <input type="button" style="background-color: #00A000" onclick="upload_file_to_server()" value="上传">
                        </td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <img src="{{$field->art_thumb}}" alt="" id="art_thumb_img" style="max-width: 200px; max-height: 100px">
                        </td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <input type="submit" value="提交">
                            <input type="button" class="back" onclick="history.go(-1)" value="返回">
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
    <script type="text/javascript">
        function upload_file_to_server() {
            var files = document.getElementById('uploadFile').files;
            var total_file = files.length;
            var formData = new FormData();
            formData.append('_token','{{csrf_token()}}');
            for (let i = 0; i < total_file; i++) {
                formData.append('file'+i,files[i]);
            }
            $.ajax({
                type: 'post',
                url: "/admin/upload", //上传文件的请求路径必须是绝对路劲
                data: formData,
                cache: false,
                processData: false,
                contentType: false,
            }).success(function (data) {
                layer.alert(data.success, {icon: 6});
                $('input[name=art_thumb]').val(data.file_path);
                $('#art_thumb_img').attr('src',data.file_path);
            }).error(function () {
                layer.alert('数据上传失败，请稍后再试试！', {icon: 5});
            });
        }
    </script>
@endsection
